package cn.sytton.taffecloud.service.system.controller;

import cn.sytton.taffecloud.common.base.doc.Api;
import cn.sytton.taffecloud.common.base.doc.ApiImplicitParam;
import cn.sytton.taffecloud.common.base.doc.ApiOperation;
import cn.sytton.taffecloud.common.base.doc.ParamType;
import cn.sytton.taffecloud.common.db.model.PageParam;
import cn.sytton.taffecloud.service.system.entity.AuthMenuTree;
import cn.sytton.taffecloud.service.system.entity.MenuEntity;
import cn.sytton.taffecloud.service.system.service.IMenuService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 菜单控制层
 *
 * @author skyrock
 */
@Api(tags = "菜单")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Resource
    private IMenuService menuService;

    @ApiOperation("查询分页菜单列表")
    @ApiImplicitParam(name = "pp", value = "分页参数对象", paramType = ParamType.query, dataTypeClass = PageParam.class)
    @GetMapping
    public PageInfo<MenuEntity> findListPage(PageParam pp) {
        return menuService.findListPage(pp);
    }

    @ApiOperation("查询单个菜单")
    @ApiImplicitParam(name = "id", value = "菜单ID", paramType = ParamType.path)
    @GetMapping("/{id}")
    public MenuEntity findById(@PathVariable String id) {
        return menuService.findById(id);
    }

    @ApiOperation("添加菜单")
    @ApiImplicitParam(name = "entity", value = "菜单数据对象", paramType = ParamType.body, dataTypeClass = MenuEntity.class)
    @PostMapping
    public void create(@RequestBody MenuEntity entity) {
        menuService.create(entity);
    }

    @ApiOperation("更新菜单")
    @ApiImplicitParam(name = "entity", value = "菜单数据对象", paramType = ParamType.body, dataTypeClass = MenuEntity.class)
    @PostMapping("/update")
    public void update(@RequestBody MenuEntity entity) {
        menuService.update(entity);
    }

    @ApiOperation("删除菜单")
    @ApiImplicitParam(name = "ids", value = "菜单ID数组", paramType = ParamType.body, dataTypeClass = String[].class)
    @PostMapping("/delete")
    public void delete(@RequestBody String[] ids) {
        menuService.delete(ids);
    }

    @ApiOperation(value = "获取当前登录人的权限菜单树")
    @GetMapping("/my")
    public List<MenuEntity> findMyMenu(){
        return menuService.findMyMenu();
    }

    @ApiOperation(value = "获取所有菜单及权限")
    @GetMapping("/auth")
    public List<AuthMenuTree> findAuthMenu() {
        return menuService.findAuthMenu();
    }
}
